
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>菜单管理</title>
    #include("../../common/res.html")
</head> 
<body class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:false">
      <table  id="tt" style="width:100%;height:100%;"></table>
      <div id="tb" style="padding:0 30px;">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="btn_search" data-options="selected:true">查询</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" id="btn_add">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" id="btn_edit">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" id="btn_remove">删除</a>
      </div>
    </div>
	<div id="wu-dialog"></div>
    <script type="text/javascript">
        $(function(){
            $('#tt').treegrid({    
                url:'#(ctx)/admin/res/getData', 
                idField:'id',    
                treeField:'name', 
                toolbar:"#tb", 
                method:'get',
                fitColumns:true,
                singleSelect:true,
                columns:[[    
                    {title:'名称',field:'name',width:100},    
                    {title:'资源地址',field:'url',width:100},
                    {title:'类型',field:'type',width:30,formatter:function(val){if(val==1){return '菜单';}else{return '功能'}}},
                    {title:'资源图标',field:'iconCls',width:100},
                    {title:'排序',field:'seq',width:30},
                    {title:'是否启用',field:'enabled',width:30,formatter:function(val){if(val==1){return '启用';}else{return '禁用'}}},
                ]]  
            });
            $("#btn_search").click(function(){
                $('#tt').treegrid('load',{
                    name: $("#searchmenuName").val()
                });
            });
        });
        var exampleImg="";
		$(function(){
			$("#btn_add").click(function(){
				$('#wu-dialog').dialog({
					closed: false,
					modal:true,
                    title: "添加资源",
                    width: 800,    
                    height: 500,
                    iconCls:'icon-save',
                    href: '#(ctx)/admin/res/edit',  
					buttons: [{
						text: '确定',
						iconCls: 'icon-ok',
						handler: function(){
							$('#ResForm').submit();
						}
					}, {
						text: '取消',
						iconCls: 'icon-cancel',
						handler: function () {
							$('#wu-dialog').dialog('close');                    
						}
                    }],
                    onLoad:function(){
                        $.getJSON('#(ctx)/admin/res/getTree',function(data){
                            data.unshift({id:0,text:'根资源',selected:true})
                            $('#pid').combotree({    
                                data:data, 
                            });
                        });
                        $('#ResForm').form({    
                            url:"#(ctx)/admin/res/saveRes",    
                            onSubmit: function(data){
                                
                            },    
                            success:function(data){    
                                data=JSON.parse(data);
                                $.messager.show({
                                    title:'消息提示',
                                    msg:data.msg,
                                    showType:'fade',
                                    style:{
                                        right:'',
                                        top:document.body.scrollTop+document.documentElement.scrollTop,
                                        bottom:''
                                    }
                                });
                                if(data.code==0){
                                    $('#tt').treegrid("reload");
                                }
                                $('#wu-dialog').dialog('close');   
                            }    
                        });
                    }
				});
			});
			
            $("#btn_edit").click(function(){
            	
                var row=$('#tt').treegrid("getSelected");
                if(!row){
                    $.messager.show({
                        title:'消息提示',
                        msg:"请选中一行",
                    });
                    return;
                }
                $('#wu-dialog').dialog({
					closed: false,
					modal:true,
                    title: "编辑栏目",
                    width: 800,    
                    height: 500,
                    iconCls:'icon-save',
                    href: '#(ctx)/admin/res/edit',  
					buttons: [{
						text: '确定',
						iconCls: 'icon-ok',
						handler: function(){
							$('#ResForm').submit();
						}
					}, {
						text: '取消',
						iconCls: 'icon-cancel',
						handler: function () {
							$('#wu-dialog').dialog('close');                    
						}
                    }],
                    onLoad:function(){
                    	 $.getJSON('#(ctx)/admin/res/getTree',function(data){
                             data.unshift({id:0,text:'根资源',selected:true})
                             $('#pid').combotree({    
                                 data:data
                             });
                             $('#ResForm').form('load',row);
                         });
                    	
                        $('#ResForm').form({
                            url:"#(ctx)/admin/res/saveRes",    
                            onSubmit: function(data){
                                data.id=row.id;
                            },    
                            success:function(data){    
                                data=JSON.parse(data);
                                $.messager.show({
                                    title:'消息提示',
                                    msg:data.msg,
                                    showType:'fade',
                                    style:{
                                        right:'',
                                        top:document.body.scrollTop+document.documentElement.scrollTop,
                                        bottom:''
                                    }
                                });
                                if(data.code==0){
                                    $('#tt').treegrid("reload");
                                }
                                $('#wu-dialog').dialog('close');   
                            }    
                        });
                    }
				});
            });

            $("#btn_remove").click(function(){
                var row=$('#tt').treegrid("getSelected");
                if(!row){
                    $.messager.show({
                        title:'消息提示',
                        msg:"请选中一行",
                    });
                    return;
                }
                $.messager.confirm('确认对话框', '是否删除'+row.name+'？', function(r){
                    if (r){
                      $.post("#(ctx)/admin/res/del",{id:row.id},function(data){
                    	  $.messager.show({
                              title:'消息提示',
                              msg:data.msg,
                              showType:'fade',
                              style:{
                                  right:'',
                                  top:document.body.scrollTop+document.documentElement.scrollTop,
                                  bottom:''
                              }
                          });
                          if(data.code==0){
                        	 $('#tt').treegrid("reload");
                          }
                      },'json');
                    }
                });

            });
		});
    </script>
</body> 
</html>
